package main.java.DMDE.model.relationships;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

import main.java.DMDE.model.CardinalityValues;
import main.java.DMDE.model.Diagram;
import main.java.DMDE.model.Entity;
import main.java.DMDE.model.relationships.strategy.ValidationStrategy;


/**
 * Class Relationship
 */
abstract public class Relationship {

	//
	// Fields
	//
    	private RelationshipComponent componentA;
    	private RelationshipComponent componentB;
    	protected ValidationStrategy validationStrategy;
    	String linkName;
    	private UUID id = null;
	//
	// Constructors
	//
    public Relationship() {}	
    	
	public Relationship(RelationshipComponent componentA, RelationshipComponent componentB,UUID id) {
	    	this.componentA = componentA;
	    	this.componentB = componentB;
	    	this.id = id;
	};

	public Relationship(UUID id) {
	    this.id = id;
	};

	public RelationshipComponent getComponentA(){
	    return componentA;
	}

	public RelationshipComponent getComponentB(){
	    return componentB;
	}
	
	public void setComponentA(RelationshipComponent componentA){
	    this.componentA = componentA;
	}
	
	public void setComponentB(RelationshipComponent componentB){
	    this.componentB = componentB;
	}
	/**
	 * Get the value of entityB
	 * 
	 * @return the value of entityB
	 */
	public Entity getEntityA() {
		return componentA.getEntity();
	}


	/**
	 * Get the value of entityB
	 * 
	 * @return the value of entityB
	 */
	public Entity getEntityB() {
		return componentB.getEntity();
	}

	
	public CardinalityValues getMaxCardinalityA() {
		return componentA.getMaxCardinality();
	}

	public CardinalityValues getMinCardinalityA() {
		return componentA.getMinCardinality();
	}

	public CardinalityValues getMaxCardinalityB() {
		return componentB.getMaxCardinality();
	}
	
	public CardinalityValues getMinCardinalityB() {
		return componentB.getMinCardinality();
	}
	
	public abstract void setDirection(Direction direction);
	
	public abstract Direction getDirection();
	
	public enum Direction {
	    ATOB, BTOA, BOTH
	}

	public List<String> getEntitiesA() {
	    return this.validationStrategy.getEntitiesA();
	}

	public List<String> getEntitiesB(String entityAName) {
	    return this.validationStrategy.getEntitiesB(entityAName);
	}

	public Entity getEntityWithName(String entityName) {
	    return this.validationStrategy.getEntityWithName(entityName);
	}

	public Iterable<RelationshipComponent> getRelationshipComponents() {
	    List<RelationshipComponent> entities = new ArrayList<RelationshipComponent>();
	    entities.add(componentA);
	    entities.add(componentB);
	    return entities;
	}

	public UUID  getId() {
	    return id;
	}

	public void setId(UUID newId) {
	    id = newId;
	}
	
	public String getLinkName() {
	    if(linkName != null)
		return linkName;
	    return "";
	}
	
	public String toString(){
	    return (this.getComponentA().getEntity().getName() + " - " + this.getComponentB().getEntity().getName());
	}

	public abstract RelationshipTypes getType();

	public void setDiagram(Diagram diagram) {
	    this.validationStrategy.setDiagram(diagram);
	}

}
